package com.msgserver.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.Cascade;

/**
 * Entity implementation class for Entity: Company
 *
 */
@Entity

public class Company extends VO implements Serializable {

	
	private static final long serialVersionUID = 1L;

	public Company() {
		super();
	}
	
	private String companyName;
	private String city;
	private String address;
	
	private Set<Employee> emps = new HashSet<Employee>();
	private Contract contract;
	private Set<CompanyAdmin> admins = new HashSet<CompanyAdmin>();
	private Set<EmployeeGroup> groups = new HashSet<EmployeeGroup>();
	private Set<Message> messages = new HashSet<Message>();

	public String getCompanyName() {
		return companyName;
	}
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	
	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
	@JoinTable(name = "Company_Emps", joinColumns = @JoinColumn(name = "companyId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "empId", referencedColumnName = "id"))
	public Set<Employee> getEmps() {
		return emps;
	}
	public void setEmps(Set<Employee> emps) {
		this.emps = emps;
	}
	
	@OneToOne(optional = false, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
	@JoinColumn(name = "contractId", referencedColumnName = "id", unique = true, nullable = false)
	@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	public Contract getContract() {
		return contract;
	}
	public void setContract(Contract contract) {
		this.contract = contract;
	}
	@OneToMany(mappedBy="company", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
	@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	public Set<CompanyAdmin> getAdmins() {
		return admins;
	}
	public void setAdmins(Set<CompanyAdmin> admins) {
		this.admins = admins;
	}
	
	
	@OneToMany(mappedBy="company", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
	@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	public Set<EmployeeGroup> getGroups() {
		return groups;
	}
	public void setGroups(Set<EmployeeGroup> groups) {
		this.groups = groups;
	}
	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
	@Cascade({ org.hibernate.annotations.CascadeType.DELETE_ORPHAN, org.hibernate.annotations.CascadeType.PERSIST,
			org.hibernate.annotations.CascadeType.MERGE })
	@JoinTable(name = "Company_msgs", joinColumns = @JoinColumn(name = "companyId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "msgId", referencedColumnName = "id"))
	public Set<Message> getMessages() {
		return messages;
	}
	public void setMessages(Set<Message> messages) {
		this.messages = messages;
	}
	
	
}
